package com.winona.code;

import java.util.ArrayList;

import com.winona.ui.LoginActivity;

import android.app.Activity;
import android.app.Application;
import android.util.Log;


public class WinonaApplication extends Application {
	private static final String TAG = "WinonaApplication";
	private ArrayList<Activity> activityList = new ArrayList<Activity>();
	private static WinonaApplication instance;

	private WinonaApplication() {
	};

	public static WinonaApplication getInstance() {
		if (instance == null) {
			instance = new WinonaApplication();
		}
		return instance;
	}

	public void addActivity(Activity activity) {
		activityList.add(activity);
	}
	
	public void removeActivity(Activity activity) {
		activityList.remove(activity);
	}
	
	public boolean isOpen() {
		return activityList.size() > 1 ? true : false;
	}
	
	public void exit(){
		for (Activity temp : activityList) {
			temp.finish();
		}
		System.exit(0);
	}
	
	public void logOut() {
		try {
			Activity act = null;
			for(Activity temp : activityList) {
				if(temp instanceof LoginActivity) {
					act = temp;
					continue;
				}
				temp.finish();
			}
			activityList.clear();
			activityList.add(act);
			ResourceManager.getInstance().releaseAll();
		} catch (Exception e) {
			Log.d(TAG, "" + e.getMessage()); 
		}
	}
}
